package com.atguigu.spring.tx.component.dao.impl;

import com.atguigu.spring.tx.component.dao.api.EmpDao;
import com.atguigu.spring.tx.entity.Employee;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

/**
 * @author : zzf
 * @date : 2021/1/5
 */

@Repository
public class EmpDaoImpl implements EmpDao {
    @Autowired
    private JdbcTemplate jdbcTemplate;

    @Override
    public void updateEmployee(Employee employee) {

    }

    @Override
    public void updateEmpName(Integer empId, String empName) {
        if (empId == 10){
            throw  new RuntimeException("我故意的");
        }
        String sql = "update t_emp set emp_name=? where emp_id=?";
        jdbcTemplate.update(sql,empName,empId);
    }

    @Override
    public String selectEmpNameById(Integer empId) {
        String sql = "select emp_name from t_emp where emp_id=?";

        return jdbcTemplate.queryForObject(sql, String.class, empId);
    }
}
